/**
 * Created by xinhuang on 15/6/6.
 */
'use strict';

describe('单元测试: realtimeServer 服务', function () {

  beforeEach(module('services.customActivity.realtime'));

  var $httpBackend, realtimeServer;
  var busVol, timeBusVol, proBusVol, userRecharge, upaySuccessRate, proBusSuccessRate;
  var proSuccessRate, provinceAllBusinessProcess, health, averageProcessTime, maxThroughput, maxTPS;
  beforeEach(inject(function ($injector) {
      realtimeServer = $injector.get('realtimeServer');
      $httpBackend = $injector.get('$httpBackend');

      realtimeServer.setActivityId(111);

      busVol = {data: {upay: 12222, tmall: 12222, scapy: 12222, bank: 12222}};
      timeBusVol = {
        data: {
          upay: {tradeAmount: 122222, volumeOfBus: 122222, volumeTime: '08:00:00'},
          tmall: {tradeAmount: 122222, volumeOfBus: 122222, volumeTime: '08:00:00'},
          scpay: {tradeAmount: 122222, volumeOfBus: 122222, volumeTime: '08:00:00'},
          bank: {tradeAmount: 122222, volumeOfBus: 122222, volumeTime: '08:00:00'}
        }
      };
      proBusVol = {data: [{provinceName: '广东', volume: 122222, volState: 1}]};
      userRecharge = {
        data: {
          upay: {rechargeAmount: ['(0,5)'], volumeOfTrans: [11], flag: ['1']},
          tmall: {rechargeAmount: ['(0,5)'], volumeOfTrans: [11], flag: ['1']},
          scpay: {rechargeAmount: ['(0,5)'], volumeOfTrans: [11], flag: ['1']},
          bank: {rechargeAmount: ['(0,5)'], volumeOfTrans: [11], flag: ['1']}
        }
      };
      upaySuccessRate = {
        data: {
          businessProcess: {rate: 99.0, rateState: 1},
          systemProcess: {rate: 99.0, rateState: 1}
        }
      };
      proBusSuccessRate = {
        data: {
          total: {rate: 99.0, rateState: 1},
          tmall: {rate: 99.0, rateState: 1},
          scpay: {rate: 99.0, rateState: 1},
          bank: {rate: 99.0, rateState: 1}
        }
      };

      provinceAllBusinessProcess = {data: [{provinceName: '广东', rate: 99.0, rateState: 1}]};
      health = {
        data: {
          tmall: 90.12,  //天猫健康度  保留2位小数，以下不再重复
          scpay: 99.12,  //移动商城健康度
          bank: 90.34,  //总对总健康度
          sumHealth: 99.01,  //总健康度
          sumHealthState: 1,  //1.优, 2.良, 3.中, 4.差
          tmallState: 1,  //1.优, 2.良, 3.中, 4.差
          bankState: 1, //1.优, 2.良, 3.中, 4.差
          scpayState: 1  //1.优, 2.良, 3.中, 4.差
        }

      };
      averageProcessTime = {data: {processTime: 2.59, tmProcessTime: 2.59, cmProcessTime: 2.59, bkProcessTime: 2.59}};
      maxThroughput = {data: {maxThroughput: 111, tmThroughput: 111, cmThroughput: 111, bkThroughput: 111}};
      maxTPS = {data: {tps: 111, tmTps: 111, bkTps: 111, cmTps: 111}};

      $httpBackend.whenPOST('/sas/customActivity/realTime/businessDayVolume/query', {activityId: 111}).respond(busVol);
      $httpBackend.whenPOST('/sas/customActivity/realTime/businessTotalVolume/query', {activityId: 111}).respond(busVol);
      $httpBackend.whenPOST('/sas/customActivity/realTime/businessTimeVolume/query', {activityId: 111}).respond(timeBusVol);
      $httpBackend.whenPOST('/sas/customActivity/realTime/businessProvinceVolume/query', {activityId: 111}).respond(proBusVol);
      $httpBackend.whenPOST('/sas/customActivity/realTime/userRechargePreference/query', {activityId: 111}).respond(userRecharge);
      $httpBackend.whenPOST('/sas/customActivity/realTime/upaySuccessRate/query', {activityId: 111}).respond(upaySuccessRate);
      $httpBackend.whenPOST('/sas/customActivity/realTime/proBusSuccessRate/query', {activityId: 111}).respond(proBusSuccessRate);
      $httpBackend.whenPOST('/sas/customActivity/realTime/proSysSuccessRate/query', {activityId: 111}).respond(proBusSuccessRate);
      $httpBackend.whenPOST('/sas/customActivity/realTime/allBusSuccessRate/query', {activityId: 111}).respond(proBusSuccessRate);
      $httpBackend.whenPOST('/sas/customActivity/realTime/allSysSuccessRate/query', {activityId: 111}).respond(proBusSuccessRate);
      $httpBackend.whenPOST('/sas/customActivity/realTime/provinceAllBusinessProcess/query', {activityId: 111}).respond(provinceAllBusinessProcess);
      $httpBackend.whenPOST('/sas/customActivity/realTime/health/query', {activityId: 111}).respond(health);
      $httpBackend.whenPOST('/sas/customActivity/realTime/averageProcessTime/query', {activityId: 111}).respond(averageProcessTime);
      $httpBackend.whenPOST('/sas/customActivity/realTime/maxThroughput/query', {activityId: 111}).respond(maxThroughput);
      $httpBackend.whenPOST('/sas/customActivity/realTime/maxTPS/query', {activityId: 111}).respond(maxTPS);
    })
  )
  ;

  it('数据获取: 当日业务量', function () {
    realtimeServer.businessDayVolume.get();
    $httpBackend.flush();
    expect(realtimeServer.businessDayVolume.data).toEqual(busVol.data);
  });

  it('数据获取: 活动期间累计业务量', function () {
    realtimeServer.businessTotalVolume.get();
    $httpBackend.flush();
    expect(realtimeServer.businessTotalVolume.data).toEqual(busVol.data);
  });

  it('数据获取: 统一支付系统健康度', function () {
    realtimeServer.health.get();
    $httpBackend.flush();
    expect(realtimeServer.health.data).toEqual(health.data);
  });

  it('数据获取: 平均处理耗时', function () {
    realtimeServer.averageProcessTime.get();
    $httpBackend.flush();
    expect(realtimeServer.averageProcessTime.data).toEqual(averageProcessTime.data);
  });

  it('数据获取: 最大吞吐量', function () {
    realtimeServer.maxThroughput.get();
    $httpBackend.flush();
    expect(realtimeServer.maxThroughput.data).toEqual(maxThroughput.data);
  });

  it('数据获取: 最大TPS', function () {
    realtimeServer.maxTPS.get();
    $httpBackend.flush();
    expect(realtimeServer.maxTPS.data).toEqual(maxTPS.data);
  });

  it('数据获取: 分时刻业务量', function () {
    realtimeServer.businessTimeVolume.get();
    $httpBackend.flush();
    expect(realtimeServer.businessTimeVolume.data).toEqual(timeBusVol.data);
  });

  it('数据获取: 用户充值偏好', function () {
    realtimeServer.userRechargePreference.get();
    $httpBackend.flush();
    expect(realtimeServer.userRechargePreference.data).toEqual(userRecharge.data);
  });

  it('数据获取: 分省业务量', function () {
    realtimeServer.businessProvinceVolume.get();
    $httpBackend.flush();
    expect(realtimeServer.businessProvinceVolume.data).toEqual(proBusVol.data);
  });

  it('数据获取: 统一支付成功率', function () {
    realtimeServer.upaySuccessRate.get();
    $httpBackend.flush();
    expect(realtimeServer.upaySuccessRate.data).toEqual(upaySuccessRate.data);
  });

  it('数据获取: 省侧业务处理成功率', function () {
    realtimeServer.proBusSuccessRate.get();
    $httpBackend.flush();
    expect(realtimeServer.proBusSuccessRate.data).toEqual(proBusSuccessRate.data);
  });
  it('数据获取: 省侧系统处理成功率', function () {
    realtimeServer.proSysSuccessRate.get();
    $httpBackend.flush();
    expect(realtimeServer.proSysSuccessRate.data).toEqual(proBusSuccessRate.data);
  });

  it('数据获取: 全业务流程业务处理成功率', function () {
    realtimeServer.allBusSuccessRate.get();
    $httpBackend.flush();
    expect(realtimeServer.allBusSuccessRate.data).toEqual(proBusSuccessRate.data);
  });
  it('数据获取: 全业务流程系统处理成功率', function () {
    realtimeServer.allSysSuccessRate.get();
    $httpBackend.flush();
    expect(realtimeServer.allSysSuccessRate.data).toEqual(proBusSuccessRate.data);
  });

it('数据获取: 分省全业务流程业务处理成功率', function () {
  realtimeServer.provinceAllBusinessProcess.get();
  $httpBackend.flush();
  expect(realtimeServer.provinceAllBusinessProcess.data).toEqual(provinceAllBusinessProcess.data);
});
})
;